package com.util.format;

import com.alibaba.fastjson.JSON;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by reeves on 2015/12/11.
 */
public class MapToJson {
    private String mapKey = "";
    private Object mapValue = null;
    Map<String, Object> jsonMap = null;
    private static final Logger LOGGER = Logger.getLogger(MapToJson.class);

    public MapToJson(String mapKey, Object mapValue) {
        this.mapKey = mapKey;
        this.mapValue = mapValue;
        jsonMap = new HashMap<>();
        jsonMap.put(this.mapKey, this.mapValue);
    }

    public String toJsonString() {
        if (jsonMap != null) {
            return JSON.toJSONString(jsonMap);
        }else {
            LOGGER.error("将Map转换成Json的类MapToJson初始化错误!");
            return "{\"result\":false}";
        }
    }
}
